<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>展示所有图书</title>
</head>
<script src="/js/jquery.js" type="text/javascript"></script>
<body>
<a th:href="@{/addBook}">添加图书</a><br/>
<div>
    <form action="/searchBooks" method="get">
        图书名称：<input type="text" name="name"/><br/>
        图书类别：<input type="text" name="category"/><br/>
        图书作者：<input type="text" name="author"/><br/>
        <input type="submit" value="搜索"/>
    </form>
</div>
<table border="1">
    <tr>
        <th>选择</th>
        <th>编号</th>
        <th>书名</th>
        <th>价格</th>
        <th>类目</th>
        <th>库存</th>
        <th>图片</th>
        <th>说明</th>
        <th>作者</th>
        <th>已售</th>
    </tr>
    <form th:action="@{/deleteBooks}" method="post" onsubmit="return submitForm()">
        <tr th:each="book:${books}">
            <td>
                <input type="checkbox" name="id" th:value="${book.id}">
            </td>
            <td th:text="${book.id}"></td>
            <td th:text="${book.name}"></td>
            <td th:text="${book.price}"></td>
            <td th:text="${book.category}"></td>
            <td th:text="${book.pnum}"></td>
            <td th:text="${book.imgurl}"></td>
            <td th:text="${book.description}"></td>
            <td th:text="${book.author}"></td>
            <td th:text="${book.sales}"></td>
        </tr>
        <input type="submit" value="删除所选" onsubmit="return submitForm()">
    </form>
</table>
</body>
<script>
    function submitForm(){
        //获取复选框所选中的值
        if ($("input[name='id']:checked").length == 0) {
            alert("没有选择要删除的");
            return false;
        }
        if (confirm("确定删除吗？")) {
            //确定删除
            return true;
        }
        return false;
    }
</script>
</html>